/* Floating project chat — matches Home.html .bnav / .nb glass styling */

.proj-chat-float {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  pointer-events: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.proj-chat-float * {
  box-sizing: border-box;
}

.proj-chat-float .proj-chat-shell,
.proj-chat-float .proj-chat-fab,
.proj-chat-float .proj-chat-panel {
  pointer-events: auto;
}

/* Collapsed trigger — same shell as .bnav */
.proj-chat-shell {
  position: relative;
  display: flex;
  align-items: center;
  padding: 5px;
  background: rgba(10, 10, 12, 0.94);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.proj-chat-float.is-open .proj-chat-shell {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.75);
}

.proj-chat-fab {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  padding: 0;
  color: rgba(255, 255, 255, 0.88);
  background: radial-gradient(circle at 38% 32%, #1c1c1e 0%, #050505 100%);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.06),
    inset 0 -2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.2s;
}

.proj-chat-fab svg,
.proj-chat-fab img.chat-ai-icon {
  width: 18px;
  height: 18px;
  display: block;
}

@media (hover: hover) and (pointer: fine) {
  .proj-chat-fab:hover {
    color: #fff;
    background: radial-gradient(circle at 38% 32%, #2a2a2e 0%, #0a0a0c 100%);
    box-shadow:
      inset 0 1px 2px rgba(255, 255, 255, 0.1),
      inset 0 -2px 6px rgba(0, 0, 0, 0.45),
      0 0 0 1px rgba(255, 255, 255, 0.14),
      0 6px 20px rgba(255, 255, 255, 0.08);
  }
}

.proj-chat-fab:active {
  transform: scale(0.96);
}

.proj-chat-fab:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
}

.proj-chat-float.is-open .proj-chat-fab {
  color: #fff;
  background: radial-gradient(circle at 38% 32%, #28282c 0%, #0a0a0c 100%);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.1),
    inset 0 -2px 6px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Expanded panel — grows with conversation, caps near full viewport */
.proj-chat-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  width: min(420px, calc(100vw - 32px));
  max-height: min(calc(100dvh - 88px), calc(100vh - 88px), 78vh);
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: rgba(10, 10, 12, 0.94);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(10px) scale(0.96);
  transform-origin: bottom center;
  transition:
    opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.28s,
    max-height 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.proj-chat-float.is-open .proj-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
}

.proj-chat-float.is-open .proj-chat-panel.has-thread {
  max-height: min(calc(100dvh - 72px), calc(100vh - 72px), 84vh);
}

.proj-chat-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.proj-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.proj-chat-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.proj-chat-avatar img {
  width: 16px;
  height: 16px;
  display: block;
}

.proj-chat-brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.proj-chat-panel-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.1px;
  color: rgba(255, 255, 255, 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.proj-chat-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.4);
}

.proj-chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5dde9a;
  box-shadow: 0 0 0 3px rgba(93, 222, 154, 0.16);
  animation: projStatusPulse 2s ease-in-out infinite;
}

@keyframes projStatusPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.proj-chat-panel-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  padding: 0;
  color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, color 0.2s;
}

.proj-chat-panel-close svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.proj-chat-panel-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
}

.proj-chat-log {
  flex: 0 1 auto;
  min-height: 88px;
  max-height: min(calc(100dvh - 250px), calc(100vh - 250px), 62vh);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.proj-chat-panel.has-thread .proj-chat-log {
  min-height: 140px;
  max-height: min(calc(100dvh - 200px), calc(100vh - 200px), 72vh);
}

.proj-chat-log .msg {
  max-width: 92%;
  padding: 8px 12px;
  border-radius: 11px;
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: -0.1px;
}

.proj-chat-log .msg.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.proj-chat-log .msg.user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.88);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.proj-chat-log .msg.is-enter {
  animation: projMsgIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.proj-chat-log .msg.bot.is-streaming::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 3px;
  vertical-align: -0.12em;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.65);
  animation: projCaretBlink 0.85s step-end infinite;
}

@keyframes projMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes projCaretBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Typing indicator — classic AI chat dots */
.proj-chat-log .msg.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
}

.proj-chat-typing-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.45);
}

.proj-chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 14px;
}

.proj-chat-typing-dots span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  animation: projTypingDot 1.05s ease-in-out infinite;
  will-change: transform, opacity;
}

.proj-chat-typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.proj-chat-typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes projTypingDot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0) scale(0.85);
  }
  40% {
    opacity: 1;
    transform: translateY(-4px) scale(1.08);
  }
}

.proj-chat-status-dot.is-busy {
  background: #f0c14a;
  box-shadow: 0 0 0 3px rgba(240, 193, 74, 0.2);
  animation: projStatusBusy 0.9s ease-in-out infinite;
}

@keyframes projStatusBusy {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .proj-chat-log .msg.is-enter {
    animation: none;
  }
  .proj-chat-typing-dots span,
  .proj-chat-status-dot,
  .proj-chat-status-dot.is-busy,
  .proj-chat-log .msg.bot.is-streaming::after {
    animation: none;
    opacity: 0.7;
    transform: none;
  }
}

.proj-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 8px 6px;
  flex-shrink: 0;
}

.proj-chat-chips.is-hidden {
  display: none;
}

.proj-chat-chip {
  padding: 6px 10px;
  border-radius: 11px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.1px;
  color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.proj-chat-chip:hover {
  border-color: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.62);
  background: rgba(255, 255, 255, 0.07);
}

.proj-chat-chip:active {
  transform: scale(0.98);
}

.proj-chat-form {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px 8px;
  flex-shrink: 0;
  touch-action: manipulation;
}

.proj-chat-form input,
.proj-chat-form input.proj-chat-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.25;
  color: rgba(255, 255, 255, 0.82);
  outline: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
  transform: none;
  transition: border-color 0.2s, background 0.2s;
}

.proj-chat-form input::placeholder {
  color: rgba(255, 255, 255, 0.28);
  font-size: 12px;
  line-height: 1.25;
}

.proj-chat-form input:focus {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.07);
  transform: none;
  zoom: 1;
}

.proj-chat-send {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  padding: 0;
  color: rgba(255, 255, 255, 0.88);
  background: radial-gradient(circle at 38% 32%, #1c1c1e 0%, #050505 100%);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.06),
    inset 0 -2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s, opacity 0.2s;
}

.proj-chat-send svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.proj-chat-send:hover {
  color: #fff;
}

.proj-chat-send:active {
  transform: scale(0.96);
}

.proj-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .proj-chat-panel,
  .proj-chat-fab,
  .proj-chat-shell {
    transition: none;
  }
}

@media (pointer: coarse), (hover: none) {
  .proj-chat-float {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 16px;
    box-sizing: border-box;
  }

  .proj-chat-panel {
    left: auto;
    right: auto;
    transform: translateY(10px) scale(0.96);
  }

  .proj-chat-float.is-open .proj-chat-panel {
    transform: translateY(0) scale(1);
  }

  .proj-chat-form input,
  .proj-chat-form input.proj-chat-input {
    font-size: 16px !important;
    line-height: 1.25 !important;
  }

  .proj-chat-form input::placeholder {
    font-size: 16px !important;
  }
}

@media (max-width: 480px) {
  .proj-chat-float {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .proj-chat-panel {
    width: min(360px, calc(100vw - 24px));
    max-height: min(calc(100dvh - 80px), 82vh);
  }

  .proj-chat-form input {
    height: 44px;
    font-size: 16px !important;
  }

  .proj-chat-log {
    max-height: min(calc(100dvh - 220px), 68vh);
  }

  .proj-chat-panel.has-thread .proj-chat-log {
    max-height: min(calc(100dvh - 180px), 74vh);
  }
}

/* iOS Safari — keyboard open inside drawer iframe: pin above keyboard, keep full panel */
@media (pointer: coarse), (hover: none) {
  html.case-study[data-embed] .proj-chat-float.is-keyboard-open {
    z-index: 10000;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    padding: 0 16px;
    box-sizing: border-box;
    transition: bottom 0.12s ease-out;
  }

  html.case-study[data-embed] .proj-chat-float.is-keyboard-open.is-open .proj-chat-shell {
    visibility: hidden;
    height: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    border: none;
    overflow: hidden;
    pointer-events: none;
  }

  html.case-study[data-embed] .proj-chat-float.is-keyboard-open.is-open .proj-chat-panel {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%) translateY(0) scale(1);
    width: 100%;
    max-width: none;
    max-height: var(--chat-panel-max-h, min(calc(var(--chat-vv-h, 100dvh) - 24px), 420px));
    opacity: 1;
    visibility: visible;
  }

  html.case-study[data-embed] .proj-chat-float.is-keyboard-open .proj-chat-log {
    max-height: var(--chat-log-max-h, min(calc(var(--chat-vv-h, 100dvh) - 200px), 280px));
  }

  html.case-study[data-embed].is-chat-typing,
  html.case-study[data-embed].is-chat-typing body {
    overscroll-behavior: none;
  }
}
